package com.google.code.jbauble.mvc.support;

import java.io.File;
import java.io.FileFilter;
import java.io.IOException;
import java.net.JarURLConnection;
import java.net.URL;
import java.net.URLDecoder;
import java.util.Enumeration;
import java.util.LinkedHashSet;
import java.util.Set;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;

public class WebLoader {
	private static String WEBINF = "WEB-INF";
	private static String CLASSES_PATH = "classes";
	
	public static String getWebConfigPath(String webPath) {
		String path = webPath;
		if (!path.endsWith(File.separator)) {
			path += File.separator;
		}
		path += WEBINF + File.separator;
		return path;
	}
	
	public static String mergePath(String path, String file) {
		String full = path;
		if (!full.endsWith(File.separator)) {
			full += File.separator;
		}
		full += file;
		return full;
	}
	
	public static String getWebClassesPath(String path) {
		String str = path;
		if (str.indexOf(WEBINF) < 0) {
			str = getWebConfigPath(str);
		}
		
		if (!str.endsWith(File.separator)) {
			str += File.separator;
		}
		str += CLASSES_PATH + File.separator;
		return str;
	}
	
	public static String getFullClassName(String pack, String className) {
		int index = className.indexOf(".");
		if (index < 0) {
			return pack + "." + className;
		}
		return pack + "." + className.substring(0, index);
	}
}
